//
//  PayView.m
//  DingDongXiChe
//
//  Created by wtjr on 2018/1/9.
//  Copyright © 2018年 xieyingze. All rights reserved.
//

#import "PayView.h"

@interface PayView()

@property (nonatomic, strong) UIView *mainView;

@property (nonatomic, strong) BaseLabel *couponsLabel;

@property (nonatomic, strong) BaseLabel *priceLabel;

@end

@implementation PayView

#pragma mark - Init

- (void)initData {
    
}

- (void)initSubViews {
    [self addSubview:self.mainView];
}

- (void)autoLayoutSubViews {
    [self.mainView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(@0);
    }];
}

#pragma mark - BaseMethod


#pragma mark - Interface


#pragma mark - Delegate


#pragma mark - TouchEvent


#pragma mark - Setter

- (void)setViewModel:(OrderViewModel *)viewModel {
    _viewModel = viewModel;
    @weakify(self);
    [RACObserve(viewModel, order_payPrice) subscribeNext:^(id  _Nullable x) {
        @strongify(self);
        self.priceLabel.text = [NSString stringWithFormat:@"需付%.2f", [x floatValue]];
    }];
    [RACObserve(viewModel, order_coupon) subscribeNext:^(id  _Nullable x) {
        @strongify(self);
        self.couponsLabel.text = [NSString stringWithFormat:@"已优惠%@元",x];
    }];
}


#pragma mark - Getter

- (UIView *)mainView {
    if (!_mainView) {
        _mainView = [UIView new];
        _mainView.backgroundColor = kCOLOR_white;
        
        //右侧按钮
        BaseButton *payButton = [BaseButton new];
        payButton.backgroundColor = kCOLOR_mainGreen;
        [payButton setButtonStyle:@"支付" titleColor:kCOLOR_white titleFont:kFONT_mainNumBoldFont(16) texrAlignment:NSTextAlignmentCenter];
        [_mainView addSubview:payButton];
        [payButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.top.bottom.equalTo(@0);
            make.width.equalTo(@(kUI_WIDTH/2));
        }];
        
        //价格
        BaseLabel *priceLabel = [BaseLabel new];
        [priceLabel setLabelStyle:@"50元" textColor:kCOLOR_mainRed textFont:kFONT_mainFont(16) texrAlignment:NSTextAlignmentLeft];
        self.priceLabel = priceLabel;
        [_mainView addSubview:priceLabel];
        [priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(@(kUI_WIDTH/6));
            make.centerY.equalTo(@0).offset(-10);
            make.height.equalTo(@20);
        }];
        
        //已优惠
        BaseLabel *couponsLabel = [BaseLabel new];
        [couponsLabel setLabelStyle:@"已优惠0元" textColor:KCOLOR_font_tint textFont:kFONT_mainFont(8) texrAlignment:NSTextAlignmentLeft];
        self.couponsLabel = couponsLabel;
        [_mainView addSubview:couponsLabel];
        [couponsLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(priceLabel);
            make.top.equalTo(priceLabel.mas_bottom).offset(5);
            make.height.equalTo(@10);
        }];
    }
    return _mainView;
}

@end
